package com.pingan.haofang.searchcloud.api.query.parser.dbobject;

import java.util.HashMap;
import java.util.Map;

import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Avg;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Count;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.CountDistinct;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Distinct;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Max;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Min;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate.Sum;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.function.Countnull;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.function.Function;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.function.GeoDist;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.function.RangeGroup;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.function.Stddev;

/**
 * 函数配置
 *
 * @author LUYI374
 * @date 2017年7月11日
 * @since 1.0.0
 */
public enum FunctionConfig {

    COUNT("count", Count.class),
    MAX("max", Max.class),
    MIN("min", Min.class),
    AVG("avg", Avg.class),
    SUM("sum", Sum.class),
    COUNTNULL("countnull", Countnull.class),
    STDDEV("stddev", Stddev.class),
    COUNT_DISTINCT("countdistinct", CountDistinct.class),
    GEO_DIST("geodist", GeoDist.class),
    DISTINCT("distinct", Distinct.class),
    RANGE_GROUP("range_group", RangeGroup.class);

    public final String name;
    public final Class<? extends Function> functionClass;

    private static final Map<String, FunctionConfig> MAP = new HashMap<String, FunctionConfig>();

    static {
        for (FunctionConfig config : values()) {
            MAP.put(config.name, config);
        }
    }

    FunctionConfig(String name, Class<? extends Function> functionClass) {
        this.name = name;
        this.functionClass = functionClass;
    }

    public static FunctionConfig getFunction(String name) {
         return MAP.get(name.toLowerCase());
    }
}
